<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../static/echarts.min.js"></script>
    <script src="../static/echarts-wordcloud.min.js"></script>
</head>

<body>
<!-- 为 ECharts 准备一个定义了宽高的 DOM -->
<div id="main" style="width: 600px;height:400px;"></div>
<div id="main1" style="width: 600px;height:400px;"></div>
<div id="main2" style="width: 600px;height:400px;"></div>
<div id="main3" style="width: 600px;height:400px;"></div>
<div id="main4" style="width: 600px;height:400px;"></div>
<div id="main5" style="width: 600px;height:400px;"></div>
<div id="main6" style="width: 600px;height:400px;"></div>
<script th:inline="javascript" type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart1 = echarts.init(document.getElementById('main'));
    var myChart2 = echarts.init(document.getElementById('main1'));
    var myChart3 = echarts.init(document.getElementById('main2'));
    var myChart4 = echarts.init(document.getElementById('main3'));
    var myChart5 = echarts.init(document.getElementById('main4'));
    var myChart6 = echarts.init(document.getElementById('main5'));
    var myChart7 = echarts.init(document.getElementById('main6'));
    // 指定图表的配置项和数据
    let yearsNum = [[${yearsNum}]];
    let authorNum = [[${authorNum}]];
    let pressNum = [[${pressNum}]];
    let commentNum = [[${commentNum}]];
    let commentDis = [[${commentDis}]];
    let priceDis = [[${priceDis}]];
    let keywordNum = [[${keywordNum}]];
    console.log(yearsNum);
    console.log(authorNum);
    console.log(pressNum);
    console.log(commentNum);
    console.log(commentDis);
    console.log(priceDis);
    console.log(keywordNum);
    function f(obj,flag) {
        var a1 = [];
        if (flag===1){
            for(var i=0;i<obj.length;i++){
                a1[i] = obj[i].key;
            }
        }
        else {
            for(var j=0;j<obj.length;j++){
                a1[j] = obj[j].score;
            }
        }
        return a1;
    }
    var option = {
        title: {
            text: '1973年到2023年每年的出版量'
        },
        tooltip: {},
        legend: {
            data: ['出版量']
        },
        xAxis: {
            data: f(yearsNum,1)
        },
        yAxis: {},
        series: [
            {
                name: '出版量',
                type: 'bar',
                data: f(yearsNum,2)
            }
        ]
    };
    var option1 = {
        title: {
            text: '作者出版数前十'
        },
        tooltip: {},
        legend: {
            data: ['出版量']
        },
        xAxis: {
            data: f(authorNum,1)
        },
        yAxis: {},
        series: [
            {
                name: '出版量',
                type: 'bar',
                data: f(authorNum,2)
            }
        ]
    };
    var option2 = {
        title: {
            text: '出版社出版数前十'
        },
        tooltip: {},
        legend: {
            data: ['出版量']
        },
        xAxis: {
            data: f(pressNum,1)
        },
        yAxis: {},
        series: [
            {
                name: '出版量',
                type: 'bar',
                data: f(pressNum,2)
            }
        ]
    };
    var option3 = {
        title: {
            text: '评论数前十'
        },
        tooltip: {},
        legend: {
            data: ['出版量']
        },
        xAxis: {
            data: f(commentNum,1)
        },
        yAxis: {},
        series: [
            {
                name: '评论数',
                type: 'bar',
                data: f(commentNum,2)
            }
        ]
    };
    var a = commentDis.map(function(o){
        var a = {value:1,name:""};
        a.value = o.score;
        a.name = o.key;
        return a;
    });
    var option4 = {
        title: {
            text: 'Referer of a Website',
            subtext: 'Fake Data',
            left: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left'
        },
        series: [
            {
                name: 'Access From',
                type: 'pie',
                radius: '50%',
                data: a,
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    var b = priceDis.map(function(o){
        var a = {value:1,name:""};
        a.value = o.score;
        a.name = o.key;
        return a;
    });
    var option5 = {
        title: {
            text: 'Referer of a Website',
            subtext: 'Fake Data',
            left: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left'
        },
        series: [
            {
                name: 'Access From',
                type: 'pie',
                radius: '50%',
                data: b,
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    var c = keywordNum.map(function(o){
        var a = {value:1,name:""};
        a.value = o.score;
        a.name = o.key;
        return a;
    });
    var option6 = {
        title: {
            text: '高频知识点词云图',
            /*subtext: '纯属虚构',*/
            left: 'center'
        },
        tooltip: {},
        series: [
            {
                type : 'wordCloud',  //类型为字符云
                shape:'smooth',  //平滑
                gridSize : 8, //网格尺寸
                size : ['50%','60%'],
                //sizeRange : [ 50, 100 ],
                rotationRange : [-45, 0, 45, 90], //旋转范围
                textStyle : {
                    normal : {
                        fontFamily:'微软雅黑',
                        color: function() {
                            return 'rgb(' +
                                Math.round(Math.random() * 255) +
                                ', ' + Math.round(Math.random() * 255) +
                                ', ' + Math.round(Math.random() * 255) + ')'
                        }
                    },
                    emphasis : {
                        shadowBlur : 5,  //阴影距离
                        shadowColor : '#333'  //阴影颜色
                    }
                },
                left: 'center',
                top: '-10%',
                right: null,
                bottom: null,
                width:'100%',
                height:'100%',
                data:c,
            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart1.setOption(option);
    myChart2.setOption(option1);
    myChart3.setOption(option2);
    myChart4.setOption(option3);
    myChart5.setOption(option4);
    myChart6.setOption(option5);
    myChart7.setOption(option6);
</script>
</body>
</html>